home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
UPC12BS2.ZIP
/
TEST
/
TESTULIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-30
|
15KB
|
545 lines
/*--------------------------------------------------------------------*/
/* Program: ulibtest.c 28 Nov 1992 */
/* Author: Andrew H. Derbyshire */
/* Kendra Electronic Wonderworks */
/* P.O. Box 132 */
/* Arlington, MA 02174-0002 USA */
/* Internet: help@kew.com */
/* Function: Driver program for testing UUPC/extended */
/* ULIB communications packages */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Copyright (c) 1992 by Kendra Electronic Wonderworks; */
/* all rights reserved except those explicitly granted */
/* through the UUPC/extended license. */
/*--------------------------------------------------------------------*/
/*
* $Id: TESTULIB.C 1.2 1992/12/30 12:26:32 plummer Exp $
*
* $Log: TESTULIB.C $
* Revision 1.2 1992/12/30 12:26:32 plummer
* Report errors
*
* Revision 1.1 1992/11/29 22:09:10 ahd
* Initial revision
*
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <signal.h>
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "hlib.h"
#include "ulib.h"
#include "catcher.h"
#include "timestmp.h"
#include "comm.h"
/*--------------------------------------------------------------------*/
/* Global variables */
/*--------------------------------------------------------------------*/
static char text[] =
"Only the first letter of each command is examined; operands are\n"
"are seperated by white space. Defaults for commands are in\n"
"parentheses. Commands may be issued out of sequence, in which case\n"
"the results are unpredictable.\n\n"
"open [port [speed [direct]]]\t(COM1, 2400, and 0 (modem))\n"
"close\n"
"send [text]\t\t\t(this help text)\n"
"Send [file]\t\t\t(console input)\n"
"receive [timeout]\t\t(5 seconds for up to 512 characters)\n"
"Receive [timeout] [file]\t(5 seconds, received.dat)\n"
"hangup\n"
"?\n"
"debuglevel (4)\n"
"quit\n";
static int opened = 0;
currentfile();
/*--------------------------------------------------------------------*/
/* h e l p */
/* */
/* Print help text */
/*--------------------------------------------------------------------*/
static void help( void )
{
puts(text);
}
int CheckErrors( void )
{
int far *stats;
stats = com_errors();
if( stats[COM_EOVFLOW] ) return( TRUE );
if( stats[COM_EOVRUN] ) return( TRUE );
if( stats[COM_EBREAK] ) return( TRUE );
if( stats[COM_EFRAME] ) return( TRUE );
if( stats[COM_EPARITY] ) return( TRUE );
if( stats[COM_EXMIT] ) return( TRUE );
if( stats[COM_EDSR] ) return( TRUE );
if( stats[COM_ECTS] ) return( TRUE );
return( FALSE );
}
void PrintErrors( void )
{
int far *stats;
stats = com_errors();
printmsg(3, "Buffer overflows: %-4d", stats[COM_EOVFLOW]);
printmsg(3, "Receive overruns: %-4d", stats[COM_EOVRUN]);
printmsg(3, "Break characters: %-4d", stats[COM_EBREAK]);
printmsg(3, "Framing errors: %-4d", stats[COM_EFRAME]);
printmsg(3, "Parity errors: %-4d", stats[COM_EPARITY]);
printmsg(3, "Transmit errors: %-4d", stats[COM_EXMIT]);
printmsg(3, "DSR errors: %-4d", stats[COM_EDSR]);
printmsg(3, "CTS errors: %-4d", stats[COM_ECTS]);
}
/*--------------------------------------------------------------------*/
/* o p e n i t */
/* */
/* Open communications port */
/*--------------------------------------------------------------------*/
static void openit( char *buf )
{
char *token,
*port = "COM1";
BPS speed = 2400;
int direct = 0;
token = strtok( buf , WHITESPACE );
if ( token != NULL )
{
port = token;
token = strtok( NULL , WHITESPACE );
}
if ( token != NULL )
{
speed = atoi(token);
token = strtok( NULL , WHITESPACE );
}
if ( token != NULL )
direct = atoi(token);
strupr( port );
printf("openline( %s, %d, %d ) -- ", port, speed, direct );
if ( CheckErrors() ) PrintErrors();
if ( openline( port, speed, direct))
printf("failed\n");
else {
printf("succeeded\n");
opened = 1;
}
if ( CheckErrors() ) PrintErrors();
} /* openit */
/*--------------------------------------------------------------------*/
/* s e n d i t */
/* */
/* Send text to communications port */
/*--------------------------------------------------------------------*/
static void sendit( char *buf )
{
char *first = buf;
int len;
if ( ! opened )
{
puts("Port isn't open ... issue o command first");
return;
}
while( (first != NULL ) && *first && ! isprint(*first))
first++;
if (( first == NULL ) || ! (*first))
first = text;
else
strcat( first, "\r\n" );
len = strlen( first );
printf( "swrite( <text>, %d) -- ", len );
len = swrite( first, len );
printf("%d characters written\n", len);
if ( CheckErrors() ) PrintErrors();
} /* sendit */
/*--------------------------------------------------------------------*/
/* r e c v e i v e i t */
/* */
/* Receive data to console from serial port */
/*--------------------------------------------------------------------*/
static void receiveit( char *buf )
{
char *token;
int timeout = 5;
int len = 512;
int actual = 0;
if ( ! opened )
{
puts("Port isn't open ... issue o command first");
return;
}
token = strtok( buf , WHITESPACE );
if ( token != NULL )
{
timeout = atoi( token );
token = strtok( NULL , WHITESPACE );
}
if ( token != NULL )
len = atoi( token );
token = malloc( len + 1 );
while( (actual < len))
{
if ( actual )
len = actual;
printf("sread( <buffer>, %d, %d ) -- ", len, timeout );
actual = sread( token, len, timeout );
printf( "%d characters available\n", actual);
if ( CheckErrors() ) PrintErrors();
timeout = 0;
if ( terminate_processing )
return;
if ( !actual )
break;
}
if ( actual )
{
token[actual] = '\0';
puts(token);
} /* if */
free( token );
} /* receiveit */
/*--------------------------------------------------------------------*/
/* s e n d f i l e */
/* */
/* Send text to communications port from file */
/*--------------------------------------------------------------------*/